package fr.upstlse.glre.client.espacededie.commun.communiquer;

import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.SuggestOracle;

import fr.upstlse.glre.client.utilitaires.ControlerUtil;

public class EmailSuggestOracle extends SuggestOracle {

	public boolean isDisplayStringHTML() {
		return true;
	}

	public void requestSuggestions(SuggestOracle.Request req,
			SuggestOracle.Callback callback) {
		ControlerUtil.getUserControlerServiceAsyncInstance().getEmails(req,
				new ItemSuggestCallback(req, callback));
	}

	class ItemSuggestCallback implements AsyncCallback {
		private SuggestOracle.Request request;
		private SuggestOracle.Callback callback;

		public ItemSuggestCallback(SuggestOracle.Request pRequest,
				SuggestOracle.Callback pCallback) {
			request = pRequest;
			callback = pCallback;
		}

		public void onFailure(Throwable error) {
			callback.onSuggestionsReady(request, new SuggestOracle.Response());
		}

		public void onSuccess(Object retValue) {
			callback.onSuggestionsReady(request, (SuggestOracle.Response) retValue);
		}
	}
}
